
'=======================================
' 执行所有测试 case
'=======================================
Private Sub test_ObjArrayScanner_ALL_case()
    ' 基础功能测试
    test_ObjArrayScanner_base
    ' toNext 测试: 每次的移动步长 = 1
    test_ObjArrayScanner_toNext_step_is_1
    ' toNext 测试: 每次的移动步长 = 任意
    test_ObjArrayScanner_toNext_step_is_any
    ' back 测试: 每次的移动步长 = 1
    test_ObjArrayScanner_toNext_back_is_1
    ' back 测试: 每次的移动步长 = 任意
    test_ObjArrayScanner_back_step_is_any
    ' ActiveIndex 测试: 活动索引测试
    test_ObjArrayScanner_ActiveIndex

    ' makr 测试:
    test_ObjArrayScanner_reset

    ' 测试初始化的起始索引 + 结束索引
    test_ObjArrayScanner_init_startindex
    test_ObjArrayScanner_init_endindex
End Sub

' 基础功能测试
Private Sub test_ObjArrayScanner_base()
    Dim arrRef As IObjArrayRef
    Set arrRef = UtilsArrayRef.createRealObjArrayRef(5)

    Dim k1 As Collection
    Dim k2 As Collection
    Dim k3 As Collection
    Dim k4 As Collection
    Dim k5 As Collection
    Dim k6 As Collection
    Set k1 = New Collection
    Set k2 = New Collection
    Set k3 = New Collection
    Set k4 = New Collection
    Set k5 = New Collection
    Set k6 = New Collection

    arrRef.Add k1
    arrRef.Add k2
    arrRef.Add k3
    arrRef.Add k4
    arrRef.Add k5
    arrRef.Add k6

    Dim scanner As ObjArrayRefScanner
    Set scanner = New ObjArrayRefScanner
    scanner.Init arrRef

    Dim i As Long
    i = 0

    Dim v As Collection
    while scanner.hasNext
        Set v = arrRef.Item(i)
        i = i + 1
        Debug.Assert scanner.peek() Is v
        Debug.Assert scanner.getNext() Is v
    Wend
End Sub


' toNext 测试: 每次的移动步长 = 1
Private Sub test_ObjArrayScanner_toNext_step_is_1()
    Dim arrRef As IObjArrayRef
    Set arrRef = UtilsArrayRef.createRealObjArrayRef(5)

    Dim k1 As Collection
    Dim k2 As Collection
    Dim k3 As Collection
    Dim k4 As Collection
    Dim k5 As Collection
    Dim k6 As Collection
    Set k1 = New Collection
    Set k2 = New Collection
    Set k3 = New Collection
    Set k4 = New Collection
    Set k5 = New Collection
    Set k6 = New Collection

    arrRef.Add k1
    arrRef.Add k2
    arrRef.Add k3
    arrRef.Add k4
    arrRef.Add k5
    arrRef.Add k6

    Dim scanner As ObjArrayRefScanner
    Set scanner = New ObjArrayRefScanner
    scanner.Init arrRef

    Debug.Assert scanner.peek() Is arrRef.Item(0)
    scanner.toNext

    Debug.Assert scanner.peek() Is arrRef.Item(1)
    scanner.toNext

    Debug.Assert scanner.peek() Is arrRef.Item(2)
    scanner.toNext

    Debug.Assert scanner.peek() Is arrRef.Item(3)
    scanner.toNext

    Debug.Assert scanner.peek() Is arrRef.Item(4)
    scanner.toNext

    Debug.Assert scanner.peek() Is arrRef.Item(5)
    scanner.toNext

    Debug.Assert scanner.peek() Is Nothing
    scanner.toNext
    Debug.Assert scanner.peek() Is Nothing
End Sub

' toNext 测试: 每次的移动步长 = 任意
Private Sub test_ObjArrayScanner_toNext_step_is_any()
    Dim arrRef As IObjArrayRef
    Set arrRef = UtilsArrayRef.createRealObjArrayRef(5)

    Dim k1 As Collection
    Dim k2 As Collection
    Dim k3 As Collection
    Dim k4 As Collection
    Dim k5 As Collection
    Dim k6 As Collection
    Set k1 = New Collection
    Set k2 = New Collection
    Set k3 = New Collection
    Set k4 = New Collection
    Set k5 = New Collection
    Set k6 = New Collection

    arrRef.Add k1
    arrRef.Add k2
    arrRef.Add k3
    arrRef.Add k4
    arrRef.Add k5
    arrRef.Add k6

    Dim scanner As ObjArrayRefScanner
    Set scanner = New ObjArrayRefScanner
    scanner.Init arrRef

    Debug.Assert scanner.peek() Is arrRef.Item(0)
    scanner.toNext(2)

    Debug.Assert scanner.peek() Is arrRef.Item(2)
    scanner.toNext(3)

    Debug.Assert scanner.peek() Is arrRef.Item(5)

    ' 这里的内部索引将会被定位到 6
    scanner.toNext(5)
    Debug.Assert scanner.peek() Is Nothing
    ' 这里的内部索引将会被定位到 6
    scanner.toNext
    Debug.Assert scanner.peek() Is Nothing
End Sub

' back 测试: 每次的移动步长 = 1
Private Sub test_ObjArrayScanner_toNext_back_is_1()
    Dim arrRef As IObjArrayRef
    Set arrRef = UtilsArrayRef.createRealObjArrayRef(5)

    Dim k1 As Collection
    Dim k2 As Collection
    Dim k3 As Collection
    Dim k4 As Collection
    Dim k5 As Collection
    Dim k6 As Collection
    Set k1 = New Collection
    Set k2 = New Collection
    Set k3 = New Collection
    Set k4 = New Collection
    Set k5 = New Collection
    Set k6 = New Collection

    arrRef.Add k1
    arrRef.Add k2
    arrRef.Add k3
    arrRef.Add k4
    arrRef.Add k5
    arrRef.Add k6

    Dim scanner As ObjArrayRefScanner
    Set scanner = New ObjArrayRefScanner
    scanner.Init arrRef

    ' 定位到最后
    scanner.toNext(100)

    scanner.back
    Debug.Assert scanner.peek() Is arrRef.Item(5)

    scanner.back
    Debug.Assert scanner.peek() Is arrRef.Item(4)

    scanner.back
    Debug.Assert scanner.peek() Is arrRef.Item(3)

    scanner.back
    Debug.Assert scanner.peek() Is arrRef.Item(2)

    scanner.back
    Debug.Assert scanner.peek() Is arrRef.Item(1)

    scanner.back
    Debug.Assert scanner.peek() Is arrRef.Item(0)

    ' 回退到 0 索引后，再次回退仍然是 0 索引
    scanner.back
    Debug.Assert scanner.peek() Is arrRef.Item(0)
End Sub

' back 测试: 每次的移动步长 = 任意
Private Sub test_ObjArrayScanner_back_step_is_any()
    Dim arrRef As IObjArrayRef
    Set arrRef = UtilsArrayRef.createRealObjArrayRef(5)

    Dim k1 As Collection
    Dim k2 As Collection
    Dim k3 As Collection
    Dim k4 As Collection
    Dim k5 As Collection
    Dim k6 As Collection
    Set k1 = New Collection
    Set k2 = New Collection
    Set k3 = New Collection
    Set k4 = New Collection
    Set k5 = New Collection
    Set k6 = New Collection

    arrRef.Add k1
    arrRef.Add k2
    arrRef.Add k3
    arrRef.Add k4
    arrRef.Add k5
    arrRef.Add k6

    Dim scanner As ObjArrayRefScanner
    Set scanner = New ObjArrayRefScanner
    scanner.Init arrRef

    ' 定位到最后 index = 6
    scanner.toNext(100)

    ' index = 6 - 2 = 4
    scanner.back(2)
    Debug.Assert scanner.peek() Is arrRef.Item(4)

    ' index = 4 - 3 = 1
    scanner.back(3)
    Debug.Assert scanner.peek() Is arrRef.Item(1)

    ' index = 1 - 2 = -1，这种情况下将会被自动纠正为 0
    scanner.back(2)
    Debug.Assert scanner.peek() Is arrRef.Item(0)
End Sub

' ActiveIndex 测试: 活动索引测试
Private Sub test_ObjArrayScanner_ActiveIndex()
    Dim arrRef As IObjArrayRef
    Set arrRef = UtilsArrayRef.createRealObjArrayRef(5)

    Dim k1 As Collection
    Dim k2 As Collection
    Dim k3 As Collection
    Dim k4 As Collection
    Dim k5 As Collection
    Dim k6 As Collection
    Set k1 = New Collection
    Set k2 = New Collection
    Set k3 = New Collection
    Set k4 = New Collection
    Set k5 = New Collection
    Set k6 = New Collection

    arrRef.Add k1
    arrRef.Add k2
    arrRef.Add k3
    arrRef.Add k4
    arrRef.Add k5
    arrRef.Add k6

    Dim scanner As ObjArrayRefScanner
    Set scanner = New ObjArrayRefScanner
    scanner.Init arrRef

    Debug.Assert scanner.ActiveIndex = 0

    scanner.toNext
    Debug.Assert scanner.ActiveIndex = 1

    scanner.toNext
    Debug.Assert scanner.ActiveIndex = 2

    scanner.toNext
    Debug.Assert scanner.ActiveIndex = 3

    scanner.toNext
    Debug.Assert scanner.ActiveIndex = 4

    scanner.toNext
    Debug.Assert scanner.ActiveIndex = 5

    scanner.toNext
    Debug.Assert scanner.ActiveIndex = 6

    scanner.toNext
    Debug.Assert scanner.ActiveIndex = 6
End Sub

' makr 测试:
Private Sub test_ObjArrayScanner_reset()
    Dim arrRef As IObjArrayRef
    Set arrRef = UtilsArrayRef.createRealObjArrayRef(5)

    Dim k1 As Collection
    Dim k2 As Collection
    Dim k3 As Collection
    Dim k4 As Collection
    Dim k5 As Collection
    Dim k6 As Collection
    Set k1 = New Collection
    Set k2 = New Collection
    Set k3 = New Collection
    Set k4 = New Collection
    Set k5 = New Collection
    Set k6 = New Collection

    arrRef.Add k1
    arrRef.Add k2
    arrRef.Add k3
    arrRef.Add k4
    arrRef.Add k5
    arrRef.Add k6

    Dim scanner As ObjArrayRefScanner
    Set scanner = New ObjArrayRefScanner
    scanner.Init arrRef

    ' 定位到最后 index = 6
    scanner.toNext(100)

    ' 1. reset，因为没有 mark，将会直接定位到 0
    scanner.reset
    Debug.Assert scanner.peek() Is arrRef.Item(0)

    ' 2. mark 后 reset
    scanner.toNext ' -> 1
    scanner.toNext ' -> 2
    scanner.mark
    scanner.toNext ' -> 3
    scanner.toNext ' -> 4
    Debug.Assert scanner.peek() Is arrRef.Item(4)
    scanner.reset ' -> 2
    Debug.Assert scanner.peek() Is arrRef.Item(2)

    ' 3. 清除 mark
    scanner.toNext ' -> 3
    scanner.toNext ' -> 4
    Debug.Assert scanner.peek() Is arrRef.Item(4)
    scanner.clearMark
    scanner.reset ' -> 0
    Debug.Assert scanner.peek() Is arrRef.Item(0)

    ' 4. 测试 resetAndClearMark
    scanner.toNext ' -> 1
    scanner.toNext ' -> 2
    scanner.mark
    scanner.toNext ' -> 3
    scanner.toNext ' -> 4
    Debug.Assert scanner.peek() Is arrRef.Item(4)
    scanner.reset ' -> 2
    scanner.toNext ' -> 3
    scanner.toNext ' -> 4
    Debug.Assert scanner.peek() Is arrRef.Item(4)
    scanner.reset ' -> 2 再次 reset 后仍然是 2
    scanner.toNext ' -> 3
    scanner.toNext ' -> 4
    scanner.resetAndClearMark ' reset 后，回到 2，并清除 mark
    Debug.Assert scanner.peek() Is arrRef.Item(2)
    scanner.reset ' -> 0 再次 reset 后，回因为没有 mark 而回退到 0
    Debug.Assert scanner.peek() Is arrRef.Item(0)
End Sub

' 测试初始化的起始索引
Private Sub test_ObjArrayScanner_init_startindex()
    Dim arrRef As IObjArrayRef
    Set arrRef = UtilsArrayRef.createRealObjArrayRef(5)

    Dim k1 As Collection
    Dim k2 As Collection
    Dim k3 As Collection
    Dim k4 As Collection
    Dim k5 As Collection
    Dim k6 As Collection
    Set k1 = New Collection
    Set k2 = New Collection
    Set k3 = New Collection
    Set k4 = New Collection
    Set k5 = New Collection
    Set k6 = New Collection

    arrRef.Add k1
    arrRef.Add k2
    arrRef.Add k3
    arrRef.Add k4
    arrRef.Add k5
    arrRef.Add k6


    Dim i As Long
    Dim v As Collection
    Dim scanner As ObjArrayRefScanner


    ' 1. 起始索引 > 0
    Set scanner = New ObjArrayRefScanner
    scanner.Init arrRef, 1

    i = 1

    while scanner.hasNext
        Set v = arrRef.Item(i)
        i = i + 1
        Debug.Assert scanner.peek() Is v
        Debug.Assert scanner.getNext() Is v
    Wend

    ' 2. 起始索引 < 0，调整后的索引为整数
    Set scanner = New ObjArrayRefScanner
    scanner.Init arrRef, -2

    i = 4

    while scanner.hasNext
        Set v = arrRef.Item(i)
        i = i + 1
        Debug.Assert scanner.peek() Is v
        Debug.Assert scanner.getNext() Is v
    Wend

    ' 3. 起始索引 < 0，调整后的索引为整数
    Set scanner = New ObjArrayRefScanner
    scanner.Init arrRef, -100

    i = 0

    while scanner.hasNext
        Set v = arrRef.Item(i)
        i = i + 1
        Debug.Assert scanner.peek() Is v
        Debug.Assert scanner.getNext() Is v
    Wend
End Sub

' 测试初始化的结束索引
Private Sub test_ObjArrayScanner_init_endindex()
    Dim arrRef As IObjArrayRef
    Set arrRef = UtilsArrayRef.createRealObjArrayRef(5)

    Dim k1 As Collection
    Dim k2 As Collection
    Dim k3 As Collection
    Dim k4 As Collection
    Dim k5 As Collection
    Dim k6 As Collection
    Set k1 = New Collection
    Set k2 = New Collection
    Set k3 = New Collection
    Set k4 = New Collection
    Set k5 = New Collection
    Set k6 = New Collection

    arrRef.Add k1
    arrRef.Add k2
    arrRef.Add k3
    arrRef.Add k4
    arrRef.Add k5
    arrRef.Add k6


    Dim i As Long
    Dim v As Collection
    Dim scanner As ObjArrayRefScanner


    ' 1. 结束索引 > 0
    Set scanner = New ObjArrayRefScanner
    scanner.Init arrRef, endIndex:= 3

    i = 0

    while scanner.hasNext
        Set v = arrRef.Item(i)
        i = i + 1
        Debug.Assert scanner.peek() Is v
        Debug.Assert scanner.getNext() Is v
    Wend
    Debug.Assert i = 4

    ' 2. 起始索引 < 0，调整后的索引为整数
    Set scanner = New ObjArrayRefScanner
    scanner.Init arrRef, endIndex:= -3

    i = 0

    while scanner.hasNext
        Set v = arrRef.Item(i)
        i = i + 1
        Debug.Assert scanner.peek() Is v
        Debug.Assert scanner.getNext() Is v
    Wend
    Debug.Assert i = 4

    ' 3. 结束索引 < 0，调整后的索引为整数
    Set scanner = New ObjArrayRefScanner
    scanner.Init arrRef, endIndex:= -100

    i = 0

    while scanner.hasNext
        Set v = arrRef.Item(i)
        i = i + 1
        Debug.Assert scanner.peek() Is v
        Debug.Assert scanner.getNext() Is v
    Wend
    Debug.Assert i = 6
End Sub